# tuple 创建
tuple1 = (1,2,3,True,'hello')
print(tuple1)
print(type(tuple1))

list1 = [1]
tuple2 = (1)
print("list:",list1)
print("tuple:",tuple2)

tuple3 = tuple()  # tuple() 类型转换
print(tuple3)

tuple4 = ()
print(tuple4)
print(type(tuple4))

tuple5 = tuple('hello')  # str -> tuple
print(tuple5)

tuple6 = tuple([1,2,3,4]) # list -> tuple
print(tuple6)

list1 = list(tuple6)  # tuple  -> list
print(list1)

# tuple 转换 str 时，str会保留()
str1 = str(tuple6)  # tuple -> str
print(str1)
print(type(str1))

# 元组的操作
# 索引
print(tuple1[-1])
# 切片
print(tuple1[::-1])
# len/max/min/sum/del

# 元组常用方法
# 统计元组内的指定关键字
a = tuple1.count('hello')
print(a)

# 寻找指定元素索引值
b = tuple1.index(2)
print(b)

# 元组的遍历
for i in tuple1:
    print(i)

for i,j in enumerate(tuple1):
    print(i,j)

for i in range(len(tuple1)):
    print(i,tuple1[i])